home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1998
/
MacHack 1998.toast
/
Sessions
/
Completions
/
Presentation Code
/
SimplifiedFileCopier.cp
< prev
Wrap
Text File
|
1998-06-19
|
2KB
|
134 lines
class FileCopier
{
private:
const FSSpec *sourceFile;
const FSSpec *destinationFile;
FileReadingPath sourcePath;
FileWritingPath destinationPath;
FileCreator create;
FileOpener open;
FileCloser close;
FileInStream inStream;
FileOutStream outStream;
InputPump pumpIn;
OutputPump pumpOut;
Race2 race;
uint8 buffer[1024 * 1024 + 4096];
Pipe pipe;
TaskSequencer<FileCopier> sequence;
typedef TaskStep<FileCopier> Step;
Step CreateDestination( bool dying, DeferredTaskTime );
Step OpenDestinationData( bool dying, DeferredTaskTime );
Step OpenSourceData( bool dying, DeferredTaskTime );
Step CopyData( bool dying, DeferredTaskTime );
Step CloseSourceData( bool dying, DeferredTaskTime );
Step CloseDestinationData( bool dying, DeferredTaskTime );
public:
FileCopier();
Task *operator()( const FSSpec& source,
const FSSpec& destination );
};
Task *FileCopier::operator()( const FSSpec& source,
const FSSpec& destination )
{
sourceFile = &source;
destinationFile = &destination;
return sequence.Start( Step( 0, &FileCopier::CreateDestination ) );
}
TaskStep<FileCopier> FileCopier::CreateDestination( bool, DeferredTaskTime )
{
return Step( create( *destinationFile ),
&FileCopier::OpenDestinationData );
}
TaskStep<FileCopier> FileCopier::OpenDestinationData( bool, DeferredTaskTime )
{
return Step( open.OpenDataFork( *destinationFile,
destinationPath ),
&FileCopier::OpenSourceData );
}
TaskStep<FileCopier> FileCopier::OpenSourceData( bool, DeferredTaskTime )
{
return Step( open.OpenDataFork( *sourceFile, sourcePath ),
&FileCopier::CopyData );
}
TaskStep<FileCopier> FileCopier::CopyData( bool, DeferredTaskTime )
{
pipe.Reset();
outStream.SetFile( destinationPath );
inStream.SetFile( sourcePath );
inStream.SuggestNoCaching();
outStream.SuggestNoCaching();
return Step( race( pumpIn( inStream, pipe.In() ),
pumpOut( pipe.Out(), outStream ),
1 ),
&FileCopier::CloseSourceData );
}
TaskStep<FileCopier> FileCopier::CloseSourceData( bool, DeferredTaskTime )
{
return Step( close( sourcePath ),
&FileCopier::CloseDestinationData );
}
TaskStep<FileCopier> FileCopier::CloseDestinationData( bool, DeferredTaskTime )
{
return Step( close( destinationPath ) );
}